﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{

    public enum Nameenum 
        {
        刘备 = 1,
        孙权,
        曹操
        }
        public enum Punch 
        {
            石头 = 1,
            剪刀,
            布
        }
    class Program
    {
           static int count = 0;
           static int pCount = 0;
           static int nCount = 0;
           static Player p = new Player();
           static NPCName nPC = new NPCName();
           static Judgment jd = new Judgment();
        static void Main(string[] args)
        {
            Totalmethod();
            
        }

        private static void Totalmethod()
        {
            Welcome();
            Spanme();
            Batlle();
            Result();
        }

        static void Spanme() 
        {
            while (true)
            {
                Console.WriteLine("出拳规则：{0}", ListPunch());
                Console.WriteLine("请选择对方角色:{0}",ListNPC());
                string cname = Console.ReadLine();
                Console.WriteLine("请输入您的姓名：");
                string bname = Console.ReadLine();
                Console.WriteLine("{0}VS{1}  对战");
                Console.WriteLine("是否开始游戏（y/n）");
                string a = Console.ReadLine();
                if (a == "y")
                {
                    break;
                }
            }
        }
        static void Batlle()
        {
            while (true)
            {
                Console.WriteLine("请出拳：{0}（输入相对应得数字）", ListPunch());
                int pf = p.PrintFrist();
                int nf = nPC.PrintFrist();
                Console.WriteLine("{0}出:{1}", p.Name, (Punch)pf);
                Console.WriteLine("{0}出：{1}", nPC.Name, (Punch)nf);
                int result = IsWin(pf, nf);

                Console.WriteLine();
                Console.WriteLine(result == 0 ? "和局！" : result == 1 ? $"恭喜！{p.Name}赢了！" : $"呃呃！{p.Name}输了！");

                count++;
                if (result == 1)
                {
                    pCount++;
                }
                else if (result == -1)
                {
                    nCount++;
                }

                Console.WriteLine("\r\n是否开始下一轮？（y/n）");
                string key = Console.ReadLine();
                if (key != "y")
                {
                    break;
                }
            }
        
        }
        static void Result() 
        {
            Console.WriteLine("\r\n===============================================");
            Console.WriteLine("{0}VS{1}",p.Name,nPC.Name);
            Console.WriteLine("对战次数：{0}",count);
            Console.WriteLine("姓名\t得分");
            Console.WriteLine("{0}\t{1}",p.Name,pCount);
            Console.WriteLine("{0}\t{1}",nPC.Name,nCount);
            Console.WriteLine("平局\t{0}",count-pCount-nCount);
            Console.WriteLine("结果："+(pCount >nCount ? p.Name:nPC.Name)+"赢了！！！！");
            Console.WriteLine("要开始下一句吗（y/n）");
            string key = Console.ReadLine();
            if (key == "y")
            {
                count = 0;
                pCount = 0;
                nCount = 0;
                Totalmethod();
            }
            else
            {
                Console.WriteLine("系统退出");
            }
        }

        private static int IsWin(int pf, int nf)
        {
            if (pf == nf)
            {
                return 0;
            }
            else if (pf == 1 && nf == 2||pf == 2 && nf ==3||pf == 3 && nf == 1)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }

        static string ListPunch() 
        {
            string punchString = " ";
            int i = 1;
            foreach (Punch n in Enum.GetValues(typeof(Punch)))
            {
                punchString += i + "、" + n + "；";
                i++;
                
            }
            return punchString;
        }

        static void Welcome() 
        {
            Console.WriteLine("---------欢迎进入游戏世界----------------------\r\n");
            Console.WriteLine("**********************************************");
            Console.WriteLine("*****************猜拳，开始*******************");
            Console.WriteLine("**********************************************");
        }

        static string ListNPC()
        {
            string roleStr = "";
            foreach (Nameenum n in Enum.GetValues(typeof(Nameenum)))
            {
                roleStr += (int)n + "、" + n + "；";
            }
            return roleStr;
        }

    }
}

